# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=avaloniailspy
pkgver=v7.2.rc.r11.g21d4939
pkgrel=1
epoch=1
groups=('blackarch' 'blackarch-decompiler')
pkgdesc='.NET Decompiler (port of ILSpy)'
arch=('x86_64')
url='https://github.com/icsharpcode/AvaloniaILSpy'
license=('MIT')
depends=('dotnet-runtime')
makedepends=('dotnet-sdk' 'git' 'libicns')
source=("$pkgname::git+https://github.com/icsharpcode/AvaloniaILSpy")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd $pkgname

  git submodule update --init --recursive
}

build() {
  cd $pkgname

  dotnet build --configuration release --output "build"
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" doc/*
  install -Dm 644 doc/license.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cp -a --no-preserve=ownership build/* "$pkgdir/usr/share/$pkgname/"

  chmod +x "$pkgdir/usr/share/$pkgname/ILSpy"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec ./ILSpy "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

